/*
 * 团队风采
 */
import 'package:flutter/material.dart';
import 'package:flutter_auth/constant/globals.dart' as globals;
import 'package:flutter_auth/common/service.dart'; // 服务接口集合
import 'package:flutter_tags/flutter_tags.dart';
import 'package:random_color/random_color.dart';
import './personWonderful.dart'; // 个人风采

class Personal extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => PersonalState();
}

class PersonalState extends State<Personal> {
  var userInfo = globals.userInfo['data'];
  List<dynamic> perList = [];
  List<Widget> chipList = [];

  @override
  void initState() {
    getUsersList(); // 根据产品线获取用户
    super.initState();
  }

  /*
  * 根据产品线获取用户
  */
  void getUsersList() {
    setState(() {
      perList = [];
    });
    getUsersByProTeam(
            {'proTeam': userInfo['proTeam'], 'userId': userInfo['id']})
        .then((result) {
      if (result['state'] && result['data'] != null) {
        setState(() {
          perList.addAll(result['data']);
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('团队风采'),
      ),
      body: _bodyWidget(),
    );
  }

  Widget _bodyWidget() {
    return Container(
      alignment: Alignment.center,
      child: Tags(
        itemCount: perList.length, // required
        itemBuilder: (int index) {
          final item = perList[index];
          RandomColor _randomColor = RandomColor();
          Color _color = _randomColor.randomColor();
          return ItemTags(
            key: Key(index.toString()),
            index: index, // required
            title: item['name'],
            activeColor: _color,
            textStyle: TextStyle(
              fontSize: 16,
            ),
            onPressed: (aItem) {
              if (item['id'] == 187) {
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return PersonWonderful();
                }));
              }
            },
          );
        },
      ),
    );
  }
}
